<template>
    <!-- 添加或修改回款明细信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="删除标志" prop="delFlag">
                                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入备注"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="回款金额" prop="backMoney">
                                <el-input v-model="form.backMoney" placeholder="请输入回款金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="回款日期" prop="backDate">
                                <el-date-picker clearable
                                                v-model="form.backDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择回款日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="备注信息" prop="infomation">
                                <el-input v-model="form.infomation" type="textarea" placeholder="请输入内容"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="项目id" prop="projectId">
                                <el-input v-model="form.projectId" placeholder="请输入项目id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="项目名称" prop="projectName">
                                <el-input v-model="form.projectName" placeholder="请输入项目名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发票id" prop="invoiceId">
                                <el-input v-model="form.invoiceId" placeholder="请输入发票id"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "GoodsFundBackForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/goodsFundBack/goodsFundBack/',
                    add:'/goodsFundBack/goodsFundBack/add',
                    edit:'/goodsFundBack/goodsFundBack/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            delFlag: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            remark: null,
            type: null,
            backMoney: null,
            backDate: null,
            infomation: null,
            projectId: null,
            projectName: null,
            invoiceId: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加回款明细信息";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改回款明细信息";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
